package com.d3works.apps.supplychain.service;

import com.d3works.apps.account.db.Invoice;
import com.d3works.apps.account.db.PaymentCondition;
import com.d3works.apps.account.db.PaymentMode;
import com.d3works.apps.base.db.Partner;
import com.d3works.apps.stock.db.StockMove;
import com.d3works.exception.D3worksException;
import com.google.inject.persist.Transactional;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;

public interface StockMoveMultiInvoiceService {

  /**
   * Generate multiple invoices and manage JPA cache from stock moves.
   *
   * @param stockMoveIdList a list of stock move ids.
   * @return an entry with the list of id of generated invoices as key, and error message as key.
   */
  Entry<List<Long>, String> generateMultipleInvoices(List<Long> stockMoveIdList);

  Map<String, Object> areFieldsConflictedToGenerateCustInvoice(List<StockMove> stockMoveList)
      throws D3worksException;

  Map<String, Object> areFieldsConflictedToGenerateSupplierInvoice(List<StockMove> stockMoveList)
      throws D3worksException;

  @Transactional(rollbackOn = {Exception.class})
  Optional<Invoice> createInvoiceFromMultiOutgoingStockMove(List<StockMove> stockMoveList)
      throws D3worksException;

  @Transactional(rollbackOn = {Exception.class})
  Optional<Invoice> createInvoiceFromMultiOutgoingStockMove(
      List<StockMove> stockMoveList,
      PaymentCondition paymentCondition,
      PaymentMode paymentMode,
      Partner contactPartner)
      throws D3worksException;

  @Transactional(rollbackOn = {Exception.class})
  Optional<Invoice> createInvoiceFromMultiIncomingStockMove(List<StockMove> stockMoveList)
      throws D3worksException;

  @Transactional(rollbackOn = {Exception.class})
  Optional<Invoice> createInvoiceFromMultiIncomingStockMove(
      List<StockMove> stockMoveList,
      PaymentCondition paymentConditionIn,
      PaymentMode paymentModeIn,
      Partner contactPartnerIn)
      throws D3worksException;

  public void checkForAlreadyInvoicedStockMove(List<StockMove> stockMoveList)
      throws D3worksException;
}
